package com.example.es.service;

import com.example.es.common.ESQueryVO;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

import java.util.List;

/**
 * 描述
 *
 * @author wangjf
 * @version 1.0
 * @createDate 2020/3/27 16:12
 * @projectName springboot-es
 */
public class ESServiceImpl<M extends ElasticsearchRepository<T, Long>, T> implements ESIService<T> {

    @Autowired
    protected M baseRepository;


    @Override
    public T save(T t) {
        return baseRepository.save(t);
    }

    @Override
    public Iterable<T> saveAll(Iterable<T> list) {

        Iterable<T> ts = baseRepository.saveAll(list);
        return ts;
    }


    @Override
    public List<T> finAll() {
        Iterable<T> its = baseRepository.findAll();
        return Lists.newArrayList(its);
    }

    @Override
    public Page<T> search(ESQueryVO query, int page, int size) {

        throw new RuntimeException("未实现");
    }


}
